/**
 * 
 */
package util;

import java.sql.DriverManager;
import java.sql.SQLException;

import metier.SalonTechniqueException;

import java.sql.*;


/**
 * @author Utilisateur
 *
 */
public class SimpleConnection {
		
	private static SimpleConnection instance=null;
	
	/**
	 * Constructeur
	 * @throws CabinetTechniqueException
	 */
	private SimpleConnection() throws SalonTechniqueException  {
		//Chargement du driver
		String driver="sun.jdbc.odbc.JdbcOdbcDriver";
		try {
			Class.forName(driver);
		}
		catch (ClassNotFoundException e)
		{
			throw new SalonTechniqueException("Erreur chargement : "+e.getMessage());
		}
	}
	
	/**
	 * Retourne une instance de la connection
	 * @return
	 * @throws CabinetTechniqueException
	 */
	public static synchronized SimpleConnection getInstance() throws SalonTechniqueException {
		
		if(instance==null)
		{
			instance=new SimpleConnection();
		}
		
		return instance;
	}
	
	
	/**
	 * Retourne la connection
	 * @return
	 * @throws CabinetTechniqueException
	 */
	public Connection getConnection() throws SalonTechniqueException {

		String url ="jdbc:odbc:COIF";

		String login ="";
		String password ="";
		Connection con=null;
		try {
			con= DriverManager.getConnection(url,login,password);
			con.setAutoCommit(false);
		}
		catch(SQLException sqle){
			throw new SalonTechniqueException("Erreur de connection : "+sqle.getMessage());
		}
		
		return con;
	}
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		try {
			Connection maCon=SimpleConnection.getInstance().getConnection();
			System.out.println(" Connection : "+maCon);
		}
		catch (SalonTechniqueException e) {
			System.out.println(e.getMessage());
		}

	}

}
